// pages/operators/orderInfo/orderInfo.js

var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    item: null,
    vInfo: null,
    goods: null,
    exp: null,
    shipChannel: null,
    shipSn: null
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const item = JSON.parse(options.item);
    this.setData({
      item
    })
    const self = this;
    wx.getStorage({
      key: 'vInfo',
      success: function (res) {
        let vInfo = res.data;
        if (vInfo) {
          self.setData({
            vInfo
          });
          self.getInfo();
        }
      }
    });
  },
  changeInput(e) {
    let changed = {};
    let prop = e.currentTarget.dataset.prop
    changed[prop] = e.detail.value;
    this.setData(changed)
  },
  getInfo() {
    let orderId = this.data.item.id;
    let vendorId = this.data.vInfo.id
    util.request(api.orderDetail, {
      orderId,
      vendorId
    }, 'POST').then(r => {
      this.setData({
        item: r.data.orderInfo,
        goods: r.data.orderGoods,
        exp: r.data.expressInfo
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  fh() {
    let vendorId = this.data.vInfo.id;
    let orderId = this.data.item.id;
    let shipSn = this.data.shipSn;
    let shipChannel = this.data.shipChannel;
    util.request(api.orderShip, {
      vendorId,
      orderId,
      shipSn,
      shipChannel
    }, 'POST').then(r => {
      if (r.errno) {
        wx.showToast({
          title: r.errmsg,
          icon:'none'
        })
      }else{
        wx.showToast({
          title: r.errmsg,
          icon:'success'
        })
        wx.navigateTo({
          url: `/pages/operators/orderInfo/orderList?cur=3`,
        })
    
      }
    })
  }
})